$(function () {
    let cookie = getCookie("username");
    console.log(cookie);

    getShoppingCart(cookie)

    // deleteGoods(cookie, ids)
    // updateGoodsCount(ids, num)
    // getAddShoppingCart(ids);
    $(".body").on('click','.del', function () {
        let goodsid = $(".body section").eq(0).attr("goodsid")
        console.log(goodsid);
$(".body").empty()
        deleteGoods(cookie, goodsid)
    })
})

function getShoppingCart(cookie) {

    $.get("../goodsAndShoppingCart/getShoppingCart.php", { "vipName": cookie },
        function (data) {
            console.log(data);
            let arr = JSON.parse(data);
            let xj = `￥${arr[0].goodsCount * arr[0].goodsPrice}.00`
            let str = '';
            str = `<section goodsid="${arr[0].goodsId}">
                 <img src="${arr[0].goodsImg}" alt="">
                 <div class="name">${arr[0].goodsName} </div>
                 <div class="btn">
                 <button>-</button>
                 <input type="text" value="${arr[0].goodsCount}">
                 <button>+</button>
                 <p>${arr[0].goodsPrice}</p>
                </div>
                <div>
                    <button class="del">删除</button>
                </div>
                </section>
                <section class="total">总计:<span></span>${xj}元</section>`
            // $(".die").attr("goodsid", arr[0].goodsId)
            // $(".body section img").attr("src", `${arr[0].goodsImg}`);
            // $(".body section .name").html(`${arr[0].goodsName}`);
            // $(".body section input").val(`${arr[0].goodsCount}`);
            // $(".body section .btn p").html(`${arr[0].goodsPrice}`);
            // $(".body .total span").html(xj);
            $(".body").append(str)

        });
}
function deleteGoods(cookie, goodsid) {
    $.get("../goodsAndShoppingCart/deleteGoods.php", { "vipName": cookie, "goodsId": goodsid },
        function (data) {
            console.log(data);
            if (data.trim() == "1") {
                alert("删除成功")
            } else {
                alert("删除出现bug了...")
            }
        });
}






